import android.os.Build
import android.text.TextUtils
import com.bsy.framework.manager.KvManager
import com.bsy.framework.utils.DeviceInfoUtils
import com.bsy.network.constant.KEY_TOKEN
import okhttp3.Interceptor
import okhttp3.Response

/**
 * @author Sincerity
 * @date   2023/3/27 07:25
 * @desc   头信息拦截器
 * 添加头信息
 */
class HeaderInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val newBuilder = request.newBuilder()
        //添加Token
        val appToken = KvManager.getString(KEY_TOKEN, "")
        if (!TextUtils.isEmpty(appToken)) {
            newBuilder.addHeader("Authorization", appToken)
            //终端（电视）尺寸
//            newBuilder.addHeader("tvsize", DeviceInfoUtils.getSize())
            newBuilder.addHeader("tvsize", "32")
            //设备厂商代码
//            newBuilder.addHeader("customer", Build.MANUFACTURER)
            newBuilder.addHeader("customer", "Skyworth")
            //设备品牌代码
//            newBuilder.addHeader("brand", Build.BRAND)
            newBuilder.addHeader("brand", "Skyworth")
            //mac地址
//            newBuilder.addHeader("mac", DeviceInfoUtils.androidId)
            newBuilder.addHeader("mac", "C4B883F80D35")
            //设备机芯代码
            newBuilder.addHeader("chip", "COOLITA")
            //设备机型代码
//            newBuilder.addHeader("model", Build.MODEL)
            newBuilder.addHeader("model", "OS")
            //国家三字代码
            newBuilder.addHeader("country", "IND")
            //设备类型，OHP：投影 TV：电视
            newBuilder.addHeader("deviceType", "TV")
            //语言
            newBuilder.addHeader("langCode", "zh")
            //屏幕分辨率
            newBuilder.addHeader("screenResolution", "2k")
            //主板制造商
//            newBuilder.addHeader("mainboardmanufacturer", Build.BOARD)
            newBuilder.addHeader("mainboardmanufacturer", "Skyworth")
            //终端操作系统版本
//            newBuilder.addHeader("osVersion", Build.VERSION.SDK_INT.toString())
            newBuilder.addHeader("osVersion", "2.0.3")
            //整机商
//            newBuilder.addHeader("tvmanufacturer", Build.MANUFACTURER)
            newBuilder.addHeader("tvmanufacturer", "JPE")
            //终端操作系统
            newBuilder.addHeader("osSystem", "Linux")
            //ui版本
            newBuilder.addHeader("uiVersion", "2.3.0")
            //浏览器名称代码
            newBuilder.addHeader("browserName", "SERAPHIC")
        }
        return chain.proceed(newBuilder.build())
    }
}